18 Lecture
CS201
Midterm & Final Term Short Notes
Files
Files in C programming are used for input and output operations. A file is a collection of related information that is stored on the disk of the computer. The standard I/O library in C provides functions like fopen(), fclose(), fread(), fwrite()
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
Which function is used to open a file in C? a) fopen() b) close() c) read() d) write() Answer: a) fopen()
Which mode is used to open a file for writing in C? a) "r" b) "w" c) "a" d) "x" Answer: b) "w"
What is the syntax for opening a file in read mode? a) fopen("filename", "r") b) fopen("r", "filename") c) fopen("filename", read) d) fopen(read, "filename") Answer: a) fopen("filename", "r")
Which function is used to close a file in C? a) close() b) fclose() c) endfile() d) finish() Answer: b) fclose()
Which function is used to write data to a file in C? a) fread() b) fwrite() c) fprintf() d) printf() Answer: b) fwrite()
Which mode is used to open a file for appending data in C? a) "r" b) "w" c) "a" d) "x" Answer: c) "a"
What is the syntax for opening a file in write mode? a) fopen("filename", "w") b) fopen("w", "filename") c) fopen("filename", write) d) fopen(write, "filename") Answer: a) fopen("filename", "w")
Which function is used to read data from a file in C? a) fread() b) fwrite() c) fprintf() d) printf() Answer: a) fread()
Which function is used to move the file pointer to a specific position within the file? a) fpos() b) fseek() c) fmove() d) fshift() Answer: b) fseek()
Which mode is used to open a file for both reading and writing in C? a) "r+" b) "w+" c) "a+" d) "x+" Answer: a) "r+"
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a file in computer science, and how is it used? Answer: A file is a collection of data or information that is stored in a computer system. It is used to store, access, and manage information in an organized manner.
What is the difference between text and binary files? Answer: Text files contain human-readable characters, while binary files contain machine-readable data in the form of bytes. Text files are used to store textual data such as documents and source code, while binary files are used to store non-textual data such as images, videos, and executables.
What are the different file modes in C programming language? Answer: The different file modes in C programming language are read mode ('r'), write mode ('w'), append mode ('a'), and read-write mode ('r+').
What is the difference between fopen() and fclose() functions in C programming? Answer: The fopen() function is used to open a file, while the fclose() function is used to close an open file.
What is the use of fseek() function in C programming? Answer: The fseek() function is used to set the file pointer to a specific position within the file.
How can you check if a file exists in C programming? Answer: The access() function can be used to check if a file exists in C programming.
What is the difference between feof() and ferror() functions in C programming? Answer: The feof() function is used to check if the end of a file has been reached, while the ferror() function is used to check if an error has occurred during file operations.
How can you read a line from a file in C programming? Answer: The fgets() function can be used to read a line from a file in C programming.
What is the difference between fread() and fwrite() functions in C programming? Answer: The fread() function is used to read data from a file, while the fwrite() function is used to write data to a file.
What is buffering in file I/O operations? Answer: Buffering refers to the process of temporarily storing data in a memory buffer before writing it to a file or reading it from a file. This is done to improve the performance of file I/O operations.